﻿namespace Chain.Wechat
{
    using Chain.BLL;
    using Chain.Model;
    using System;
    using System.Runtime.CompilerServices;
    using System.Xml;

    public class EventRequest : IRequest
    {
        
        private string _Event;

        public EventRequest(XmlDocument input) : base(input)
        {
            XmlNode root = base.XmlDoc.FirstChild;
            this.Event = root["Event"].InnerText;
            base.RequestEvent += new IRequest.RequestEventHandler(this.EventReqeustEventHandler);
        }

        public string EventReqeustEventHandler()
        {
            Chain.BLL.Mem membll = new Chain.BLL.Mem();
            Chain.BLL.MicroWebsiteSceneStr bll = new Chain.BLL.MicroWebsiteSceneStr();
            switch (this.Event)
            {
                case "subscribe":
                {
                    Chain.Model.Mem memmodel = membll.GetMemWeiXinCardModel(base.FromUserName, "MemWeiXinCard");
                    if (memmodel != null)
                    {
                        memmodel.MemAttention = 1;
                        membll.Update(memmodel);
                    }
                    return new TextResponse(this, new BusinessLogic().GetWelcomeText()).Result();
                }
                case "unsubscribe":
                {
                    bll.Delete(base.FromUserName);
                    Chain.Model.Mem memmodels = membll.GetMemWeiXinCardModel(base.FromUserName, "MemWeiXinCards");
                    if (memmodels != null)
                    {
                        memmodels.MemAttention = 2;
                        membll.Update(memmodels);
                    }
                    return string.Empty;
                }
            }
            return string.Empty;
        }

        public string Event
        {
            
            get
            {
                return this._Event;
            }
            
            set
            {
                this._Event = value;
            }
        }
    }
}

